package com.ywdnf.javaruntimecompile.web.controller;

import com.ywdnf.javaruntimecompile.core.service.RuntimeCompileService;
import com.ywdnf.javaruntimecompile.model.FrontClz;
import com.ywdnf.javaruntimecompile.model.Result;
import com.ywdnf.javaruntimecompile.util.ResultUtils;
import java.io.IOException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.thymeleaf.util.StringUtils;

/**
 * fun controller
 *
 * @author lss
 * @date 2019-05-09, Thu
 */
@RestController
@RequestMapping("/api")
public class FunController {

  @Autowired
  private RuntimeCompileService rcService;

  @RequestMapping(value = "/car", method = {RequestMethod.GET, RequestMethod.POST})
  public Result compileAndReturn(FrontClz clz) throws IOException {
    if (clz == null || StringUtils.isEmpty(clz.getCode())) {
      return ResultUtils.newFailedResult("【 clz 】参数不能为空");
    }
    System.out.println(clz.getCode());
    return rcService.compileAndGetResult(clz.getCode());
  }


}
